<template>
  <div class="enter-in">

    <honexun-header-user v-show="!isShow"></honexun-header-user>
    <!--头部区域-->
    <honexun-header>
      <headers :showLogin="isShow"></headers>
    </honexun-header>
    <!--内容区域-->
    <router-view />
    <!--底部区域-->
    <div class="bottom-area">
      <honexun-footer></honexun-footer>
    </div>
  </div>
</template>

<script>
import honexunHeader from '@/layout/header_A';
import honexunHeaderUser from '@/layout/header_B';
import headers from '@/layout/header_left_A';
import honexunFooter from '@/layout/footer_C';


export default {
  components: {
    honexunHeader,
    honexunFooter,
    headers,
    honexunHeaderUser
  },
  methods: {
    // 初始化数据及路径
    init () {
      if (this.tokenValue) {
        this.$store.dispatch('user/toFilterUserTenants', true).then(() => {
          if (!this.currentTenant) {
            return;
          }
          let auditStatus = Number(this.currentTenant.auditStatus), type = Number(this.currentTenant.type);
          let path = '';
          switch (type) {
            // 2s
            case 1:
              // 提交中 之前的状态
              if (this.preStatus.indexOf(auditStatus) !== -1) {
                path = '/enter/enterView/firmApprove2s';
              }
              if (this.underReviewStatus === auditStatus) {
                path = '/enter/enterView/approve'
              }
              if (this.rejectStatus === auditStatus) {
                path = '/enter/enterView/approve'
              }
              break;
            // 4s 供应商
            case 2:
            //供应商
            case 3:
              // 提交中 之前的状态
              if (this.preStatus.indexOf(auditStatus) !== -1) {
                path = '/enter/enterView/supplier';
              }
              if (auditStatus === this.underReviewStatus) {
                path = '/enter/enterView/approve'
              }
              if (this.rejectStatus === auditStatus) {
                path = '/enter/enterView/approve'
              }
              break;
            default:
              console.error('代码出现问题，请及时处理');
              break;
          }
          if (path !== this.path) {
            this.$router.push(path);
          }
        })
      }
    }
  },
  beforeCreate () {
  },
  mounted () {
    this.init();
    this.isShow = !this.tokenValue;
  },
  data () {
    return {
      isShow: true,
      preStatus: [0, 4],
      passedStatus: 2,
      underReviewStatus: 1,
      rejectStatus: 3
    }
  },
  computed: {
    tokenValue () {
      return this.$store.state.user.tokenValue
    },
    currentTenant () {
      return this.$store.state.user.currentTenant
    },
    path () {
      return this.$route.path
    }
  },
  watch: {
    tokenValue (newVal) {
      this.isShow = !newVal;
    }
  }
}
</script>

<style lang="less" scoped>
.enter-in {
  background: @greyDeepBackground;
  min-height: 100%;

  .bottom-area {
    padding-bottom: 80px;
  }
}
</style>
